﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MQC.send
{
    public partial class FAAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void CreateBatch_Click(object sender, EventArgs e)
        {
            string strNum = TbNum.Value.Trim();
            if(IsNoRun(strNum)==false)
            {
                string s = string.Format("<script>alert('数量必须是整数')</script>");
                Response.Write(s);
            }
            else
            {
                Maktx = TbMaktx.Value.Trim().ToUpper().ToString();
                Mold = TbMold.Value.Trim().ToUpper().ToString();
               // Proce = TbProce.Value.Trim().ToString();
                Proce = DDProce.Text.ToString();
                Num = int.Parse(TbNum.Value.Trim());
                Ps = TbPs.Value.Trim().ToString();

                using (DbAppDataContext db = new DbAppDataContext())
                {
                    var maxId = db.FA_Record.Max(c => c.Id);
                    maxId += 1;
                    string date = DateTime.Now.ToString("yyyyMMdd");
                    string[] strs = { Mold, Maktx, date, "F" + maxId.ToString() };
                    FA_Record data = new FA_Record();
                    data.Batch = string.Join("_", strs);
                    data.Maktx = Maktx;
                    data.Mold = Mold;
                    data.Proce = Proce;
                    data.Num = Num;
                    data.CreateDate = DateTime.Now;
                    data.ChangeDate = DateTime.Now;
                    data.Status = 0;
                    data.Ps = Ps;
                    db.FA_Record.InsertOnSubmit(data);
                    db.SubmitChanges();
                    Response.Write("<script>alert('创建成功')</script>");//创建成功
                }
            }
            
        }

        public bool IsNoRun(string strNum)
        {
            bool result;
            int a;
            if(int.TryParse(strNum,out a)==true)
            {
                result = true;
            }
            else { result = false; }
            return result;
        }

        
    }
}